//
//  FirstPageViewController.m
//  LBSCar
//
//  Created by dlios on 15/5/21.
//  Copyright (c) 2015年 lyz. All rights reserved.
//

#import "FirstPageViewController.h"

@interface FirstPageViewController ()

// 循环图片数组
@property(nonatomic, retain) NSMutableArray *imageArray;

@end

@implementation FirstPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    // 定位服务管理对象初始化
//    self.locationManager = [[CLLocationManager alloc] init];
//    // 设置代理
//    self.locationManager.delegate = self;
//    //
//    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; // 定位精度 六个常量
//    self.locationManager.distanceFilter = 1000.0f; // 距离过滤器 单位米
//    [_locationManager release];
    
    // 循环图片
    // 初始化循环图片数组
    self.imageArray  = [NSMutableArray array];
    // 数组中添加图片
    for (int i = 0; i < 4; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i]];
        [self.imageArray addObject:image];
    }
    // 初始化scrollView
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 150)];
    self.scrollView.bounces = NO;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.contentOffset = CGPointMake(self.view.frame.size.width, 0);
    // 设置显示图片的张数
    self.scrollView.contentSize = CGSizeMake(self.view.bounds.size.width * self.imageArray.count, self.scrollView.bounds.size.height);
    // 添加imageView到scrollView
    for (int i = 1; i < self.imageArray.count + 2; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.scrollView.bounds.size.width * i, 0, self.scrollView.bounds.size.width, self.scrollView.bounds.size.height)];
        imageView.image = [self.imageArray objectAtIndex:(i - 1) % self.imageArray.count];
        [self.scrollView addSubview:imageView];
        [imageView release];
    }
    UIImageView *imageView0 = [[UIImageView alloc] initWithFrame:CGRectMake(self.scrollView.bounds.size.width * 0, 0, self.scrollView.bounds.size.width, self.scrollView.bounds.size.height)];
    imageView0.image = [self.imageArray objectAtIndex:(self.imageArray.count - 1)];
    [self.scrollView addSubview:imageView0];
    [imageView0 release];
    // 添加scrollview到视图
    [self.view addSubview:self.scrollView];
}

//- (void)viewWillAppear:(BOOL)animated {
//    [super viewWillAppear:animated];
//    // 开始定位
//    [self.locationManager startUpdatingLocation];
//}
//
//- (void)viewWillDisappear:(BOOL)animated {
//    [super viewWillDisappear:animated];
//    // 停止定位
//    [self.locationManager stopUpdatingLocation];
//}

#pragma mark Core Location 代理方法
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    CLLocation *currLocation = [locations lastObject];
    self.lat = [NSString stringWithFormat:@"%3.5f", currLocation.coordinate.latitude];
    NSLog(@"-----lat = %@", self.lat);
    self.lng = [NSString stringWithFormat:@"%3.5f", currLocation.coordinate.longitude];
    NSLog(@"-------lng = %@", self.lng);
    self.alt = [NSString stringWithFormat:@"%3.5f", currLocation.altitude];
    NSLog(@"-----alt = %@", self.alt);
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"---error--:%@", error);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
